﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarrageGrab
{
    public partial class GiftSelectForm : Form
    {
        public List<DataGridViewRow> selList { get; set; }
        public GiftSelectForm()
        {
            InitializeComponent();
            dgv.AutoGenerateColumns = false;
            DataTable dataTable = DbHelperSQLite.Query("select * from live_gift").Tables[0];
            dgv.DataSource = dataTable;
            selList = new List<DataGridViewRow>();
        }

        private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                dgv.Rows[e.RowIndex].Cells[0].Value = !Convert.ToBoolean(dgv.Rows[e.RowIndex].Cells[0].Value);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgv.Rows)
            {
                DataGridViewCheckBoxCell? checkBox = row.Cells["selectrow"] as DataGridViewCheckBoxCell;
                if (checkBox != null && checkBox.Value != null)
                {
                    bool isChecked = (bool)checkBox.Value;
                    if (isChecked)
                    {
                        selList.Add(row);
                    }
                }
            }
            this.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            Boolean ck = cbAll.Checked;
            foreach (DataGridViewRow row in dgv.Rows)
            {
                DataGridViewCheckBoxCell? checkBox = row.Cells["selectrow"] as DataGridViewCheckBoxCell;
                //checkBox.Selected = ck;
                checkBox.Value = ck;
            }
        }
    }
}
